<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ESDKID管理</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>

<script type="text/javascript">


	function doAdd(){
		//alert("增加...");
	$('#haha').show();
		//$("input[name='sId']").val('-1');
		$('#addStandardWindow').form('clear');
		$('#addStandardWindow *').trigger('blur');// 离焦
		$('#addStandardWindow').window("open").window('setTitle', '生成ESDKID');
		$("input[name='dId']").val('-1');
	}
	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#searchcontent').val();
/* 		if(!searchcontent){return}
 */	     queryParams.buyerName = searchcontent;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){
		reloadgrid();
	}
	
	
	


	// 定义列
	var columns = [ [ {
		field : 'staffName',
		title : '经手人',
		width : 80,	
	},{
		field : 'buyerName',
		title : '客户名称',
		width : 220,	
	},{
		field : 'sdkId',
		title : '序列号',
		width : 160,
	},{
		field : 'sdkPwd',
		title : '秘钥',
		width : 160,
	},{
		field : 'registerTime',
		title : '生成时间',
		width : 160,
		formatter:formatterDate
	},{
		field : 'endTime',
		title : '到期时间',
		width : 160,
		formatter:formatterDate
	},{
		field : 'maxClient',
		title : '授权客户端数',
		width : 80,
	},{
		field : 'clientSUM',
		title : '已用客户端数',
		width : 80,
	},{
		field : 'bSId',
		title : '操作',
		width : 160,
		formatter:formatterSdkId
	} ] ];
	
	function formatterSdkId(value,row,index){
		sdkId = "'"+row.sdkId+"'";
		
		return "<a onclick=doProcess("+sdkId+") href=#>查看上传数据</a>";
	
		
	}
	
	
	
	function doProcess(sdkId){
	    if(sdkId){ 
	    	var  a = "${pageContext.request.contextPath}/page.sdksdata.ashx?sdkId="+sdkId;
 			location.href=a;

		}
	}
	
	function formatterDate(value,row,index){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	

	

	$(function(){
		$('#add').click(doAdd);
		$('#search').click(doSearch);
		$('#edit').click(doEdit);
	});
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/page.buyerSdkList.ashx",
			idField : 'bSId',
			columns : columns,
			pageList: [10,30,60],
			pagination:true,
			view:myview,
			queryParams:{BType:1},
			emptyMsg:"<font size=5>暂无记录</font>"			
		});
		
		//初始化销售员窗口
		$('#addStandardWindow').window({
            title: '部门详情',
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
		//初始化销售员窗口
		$('#editWindow').window({
            title: '部门详情',
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
		
		
		//提交表单
		$('#save').click(function(){
			
			var dateStr = $("#endTime_add").datebox('getValue');
			var timestamp = parseInt(new Date().getTime()/1000)+365*24*60*60;
			if(dateStr!=null&&dateStr.trim()!=""){
				timestamp = Date.parse(new Date(dateStr))/1000;
			}
			
			
			
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					if(timestamp){
						var params = $('#sform').serialize()+'&BType=1&endTime='+timestamp;
					}else{
						var params = $('#sform').serialize()+'&BType=1';
					}
					
					
					
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.saveBuyerSdk.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#addStandardWindow').window('close');
							// 清除表单数据
							$("input[name='sId']").val('');
							$('#addStandardWindow').form('clear');
							$('#addStandardWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data=="alreadyExist"){
							$.messager.alert('消息','该客户已经申请了ESDKID','info');

						}
						else{
							$.messager.alert('消息','操作失败','info');

						}
							
					});
				}
				
			});	
		
		
	});
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});
	

		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	<div id="haha" hidden="hidden">
	<div class="easyui-window" title="修改ESDKID" id="editWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="saveEdit" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >修改ESDKID</a>
			</div>
		</div>
		<div  id ="container" region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sformEdit">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">ESDK详情</td>
					</tr>
					<tr>
						<td>客户名称</td>
						<td id="td_cname">
						<input  class="easyui-combobox"   editable="false",
									required="true"
									name="buyerId"
									data-options="
											url:'${pageContext.request.contextPath}/page.buyerListAll.ashx?refreshcache=new Date().getTime()',
											method:'get',
											valueField:'bId',
											textField:'bName',
											panelHeight:'300'
						">						</td>
					</tr><tr>
					<td>到期时间</td>
						<td id="td_endTime">
							<input  id="endTime" editable="false" name="endTime_str"  type="text" class="easyui-datebox">
						</td>
					</tr>
					<tr>
					<td id="td_comment" colspan="2">*到期时间若是不填写，则默认日期限制为一年。</td>
					</tr><tr>
					<td>授权客户端数</td>
						<td id="td_maxClient">
							<input id="maxClient" name="maxClient" type="text" class="easyui-validatebox"  required="true">
						</td>
					</tr>	
					<input hidden="hidden" id="sdkId" name="sdkId" type="text" class="easyui-validatebox"  required="true">
						
					</table>
			</form>
		</div>
		
	</div>
	
	<div  class="easyui-window" title="添加ESDKID" id="addStandardWindow" collapsible="false" minimizable="false" maximizable="false" style="top:50px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >生成ESDKID</a>
			</div>
		</div>
		<div  id ="container" region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="sform">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">ESDK详情</td>
					</tr>
					<tr>
						<td>客户名称</td>
						<td id="td_cname">
						<input  class="easyui-combobox"   editable="false",
									required="true"
									name="buyerId"
									data-options="
											url:'${pageContext.request.contextPath}/page.buyerListAll.ashx?refreshcache=new Date().getTime()',
											method:'get',
											valueField:'bId',
											textField:'bName',
											panelHeight:'300'
						">						</td>
					</tr><tr>
					<td>到期时间</td>
						<td id="td_endTime">
							<input editable="false" id="endTime_add" name="endTime_str"  type="text" class="easyui-datebox">
						</td>
					</tr>
					<tr>
					<td id="td_comment" colspan="2">*到期时间若是不填写，则默认日期限制为一年。</td>
					</tr><tr>
					<td>授权客户端数</td>
						<td id="td_maxClient">
							<input id="maxClient" name="maxClient" type="text" class="easyui-validatebox"  required="true">
						</td>
					</tr>		
					</table>
			</form>
		</div>
		
	</div>
	</div>
	
	
		<div id="tb" hidden="hidden" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" id="add" class="easyui-linkbutton" iconCls="icon-add" plain="true" >增加</a>
 			<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
<!--  			<a href="#" id="edit" class="easyui-linkbutton" iconCls="icon-search" plain="true">编辑记录</a>
 -->			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;客户名称: <input id="searchcontent" class="easyui-textbox" style="width:80px">
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		
		</div>
	</div>
</body>

<script type="text/javascript">

//提交表单
$('#saveEdit').click(function(){
	
	var dateStr = $("#endTime").datebox('getValue');
	var timestamp = parseInt(new Date().getTime()/1000)+365*24*60*60;
	if(dateStr!=null&&dateStr.trim()!=""){
		timestamp = Date.parse(new Date(dateStr))/1000;
	}
	
	
	
		// 校验
		if($('#sformEdit').form('validate')){
			// 1 、获得form 数据
			
			var params = $('#sformEdit').serialize()+'&BType=1&endTime='+timestamp;
			
			
			// 2、将数据发送给服务器 
			$.post("${pageContext.request.contextPath}/page.saveBuyerSdk.ashx", params , function(data){
				if(data == "success"){
					// 成功
					$.messager.alert('消息','操作成功 ','info');
					// 关闭窗口
					$('#editWindow').window('close');
					// 清除表单数据
					$("input[name='sId']").val('');
					$('#editWindow').form('clear');
					$('#editWindow *').trigger('blur');// 离焦
					
					// 刷新表格数据 
					$('#grid').datagrid('reload');
				}else if(data=="alreadyExist"){
					$.messager.alert('消息','该客户已经申请了ESDKID','info');

				}
				else{
					$.messager.alert('消息','请将浏览器切换到极速模式（点击地址栏最右侧e图标，图标变为闪电 ）并重新登录后重试','info');

				}
					
			});
		}
		
	});	


function doEdit(){
	
	$('#haha').show();
	var rowData = $('#grid').datagrid('getSelected');  
    
    if (rowData == null) {  
        $.messager.alert("提示", "请选择要修改的行！", "info");  
    } else{
    $('#saveEdit').linkbutton({text:'修改ESDKID'});
    	
    	$("#sdkId").val(rowData.sdkId);
    	$("#td_cname").empty();
    	$("#td_cname").append(rowData.buyerName);
      	$("#maxClient").val(rowData.maxClient);
    
 		$("#endTime").datebox('setValue',formatterDate(rowData.endTime)); 
		
 		// 弹出窗口
		$("#editWindow").window('open').window('setTitle', '修改ESDKID');
    } 
}




</script>
</html>

